//
//  Cloud_tableViewCellTwo.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Cloud_tableViewCellTwo.h"
#import "BaseView.h"
#import "Masonry.h"

@interface Cloud_tableViewCellTwo ()<UITextFieldDelegate>
@property (nonatomic, strong) BaseView *View;
@property (nonatomic, strong) UIView *viewLineO;
@property (nonatomic, strong) UIView *viewLineT;
@property (nonatomic, strong) UIView *viewLineS;
@property (nonatomic, strong) UIView *viewLineF;
@end

@implementation Cloud_tableViewCellTwo

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
        [self createSubview];
    }
    return self;
}

- (void)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is == NO) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
}
- (void)dayTime:(NSNotification *)sender
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
}

- (void)createSubview
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    // 背景view
    _View = [[BaseView alloc] init];
    _View.backgroundColor = [UIColor whiteColor];
    _View.layer.masksToBounds = YES;
    _View.layer.cornerRadius = 10;
    [self.contentView addSubview:_View];
    // textField
    _textFieldPlace = [[BaseTextField alloc] init];
    _textFieldPlace.delegate = self;
    _textFieldPlace.placeholder = @"养殖场地址:";
    [_View addSubview:_textFieldPlace];
    
    _textFieldDetailPlace = [[BaseTextField alloc] init];
    _textFieldDetailPlace.delegate = self;
    _textFieldDetailPlace.placeholder = @"纤细地址:";
    [_View addSubview:_textFieldDetailPlace];
    
    // lable
    _lableAll = [[BaseLabel alloc] init];
    _lableAll.text = @"养殖总量";
    [_View addSubview:_lableAll];
    _lableKind = [[BaseLabel alloc] init];
    _lableKind.text = @"动物种类";
    [_View addSubview:_lableKind];
    _lableDayAge = [[BaseLabel alloc] init];
    _lableDayAge.text = @"日龄";
    [_View addSubview:_lableDayAge];
    // textfield
    _textFieldAll = [[BaseTextField alloc] init];
    _textFieldAll.delegate = self;
    _textFieldAll.placeholder = @"养殖总量";
    [_View addSubview:_textFieldAll];
    _textFieldKind = [[BaseTextField alloc] init];
    _textFieldKind.delegate = self;
    _textFieldKind.placeholder = @"动物种类";
    [_View addSubview:_textFieldKind];
    _textFieldDayAge = [[BaseTextField alloc] init];
    _textFieldDayAge.delegate = self;
    _textFieldDayAge.placeholder = @"日龄";
    [_View addSubview:_textFieldDayAge];
    
    // 横线
    _viewLineO = [[UIView alloc] init];
    _viewLineO.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineO];
    _viewLineT = [[UIView alloc] init];
    _viewLineT.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineT];
    _viewLineS = [[UIView alloc] init];
    _viewLineS.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineS];
    _viewLineF = [[UIView alloc] init];
    _viewLineF.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineF];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
    }];
    // textField
    [_textFieldPlace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_View.mas_top);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.2);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
    }];

    [_textFieldDetailPlace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_textFieldPlace.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.2);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
    }];

    
    // lable 的约束
    [_lableAll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_textFieldDetailPlace.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.2);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableKind mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableAll.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.2);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableDayAge mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableKind.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.2);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    // textfield 的约束
    [_textFieldAll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableAll.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldDetailPlace.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableAll.mas_height);
    }];
    [_textFieldKind mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableKind.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldAll.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableAll.mas_height);
    }];
    [_textFieldDayAge mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableDayAge.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldKind.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableAll.mas_height);
    }];
    
    // 横条
    [_viewLineO mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldPlace.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldDetailPlace.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldAll.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldKind.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];

}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}



@end
